# == Class: eos
#
# Full description of class eos here.
#
# === Parameters
#
# Document parameters here.
#
# [*sample_parameter*]
#   Explanation of what this parameter affects and what it defaults to.
#   e.g. "Specify one or more upstream ntp servers as an array."
#
# === Variables
#
# Here you should define a list of variables that this module would require.
#
# [*sample_variable*]
#   Explanation of how this variable affects the funtion of this class and if
#   it has a default. e.g. "The parameter enc_ntp_servers must be set by the
#   External Node Classifier as a comma separated list of hostnames." (Note,
#   global variables should be avoided in favor of class parameters as
#   of Puppet 2.6.)
#
# === Examples
#
#  class { eos:
#    servers => [ 'pool.ntp.org', 'ntp.local.company.com' ],
#  }
#
# === Authors
#
# Author Name <author@domain.com>
#
# === Copyright
#
# Copyright 2014 Your name here, unless otherwise noted.
#
class eos (
  $enable_eos  = true,
  $enable_eosd = true,
  $enable_autofs = false,
)
{
if 0 + $operatingsystemmajrelease >=6 {
if $enable_eos {

  if 0 + $operatingsystemmajrelease >=7 {
    package { ["xrootd-client",
          	"xrootd-devel",
          	"xrootd-client-libs",
          	"xrootd-libs"]:
        ensure   => "installed",
        require  => Yumrepo['site'],
    }
  }
  else {
    package { ["xrootd-client",
                  "xrootd-devel",
                  "xrootd-client-libs",
                  "xrootd-compat-client-libs",
                  "xrootd-compat-libs",
                  "xrootd-libs"]:
        ensure   => "installed",
        require  => Yumrepo['site'],
    }
  }
  package { ["eos-fuse-core",
             "eos-client",
             "eos-fuse-sysv",
	     "eos-fusex",
	     "eos-fusex-selinux",
	     "eos-fusex-core"]:
      ensure   => "installed",
      require  => Yumrepo['site'],
  }->
  if $enable_autofs {
    file {"/etc/sysconfig/eos.asg":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      source     =>  "puppet:///modules/${module_name}/sysconfig/eos.asg",
    }
    file {"/etc/sysconfig/eos.argo":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      source     =>  "puppet:///modules/${module_name}/sysconfig/eos.argo",
    }
    file {"/etc/sysconfig/eos.user":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      source     =>  "puppet:///modules/${module_name}/sysconfig/eos.user",
    }
    file {"/etc/sysconfig/eos.lhaaso":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      source     =>  "puppet:///modules/${module_name}/sysconfig/eos.lhaaso",
    }
    file {"/etc/sysconfig/eos.public":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      source     =>  "puppet:///modules/${module_name}/sysconfig/eos.public",
    }
    file {"/etc/sysconfig/eos.wcda":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      source     =>  "puppet:///modules/${module_name}/sysconfig/eos.wcda",
    }
    #file {"/etc/sysconfig/eos.hxmt":
    #  mode       =>  '644',
    #  owner      =>  'root',
    #  group      =>  'root',
    #  source     =>  "puppet:///modules/${module_name}/sysconfig/eos.hxmt",
    #}
    file {"/etc/sysconfig/eos.besfs3":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      source     =>  "puppet:///modules/${module_name}/sysconfig/eos.besfs3",
    }
    file {"/etc/autofs.conf":
      mode       =>  '644',
      owner      =>  'root',
      group      =>  'root',
      source     =>  "puppet:///modules/${module_name}/autofs.conf",
    }
    if 0 + $operatingsystemmajrelease >=7 {    
      file {"/etc/auto.master.d/eos.autofs":
        mode         =>  '644',
        owner        =>  'root',
        group        =>  'root',
        source       =>  "puppet:///modules/${module_name}/eos.autofs",
      }
    }
    file {"/etc/auto.eos":
      mode         =>  '644',
      owner        =>  'root',
      group        =>  'root',
      source       =>  "puppet:///modules/${module_name}/auto.eos",
    }
    package { "eos-config-ui":
      ensure   => "installed",
      require  => Yumrepo['site'],
    }
    package { "eos-config":
      ensure   => "absent",
    }

  }
  else {
    package { "eos-config":
      ensure   => "installed",
      require  => Yumrepo['site'],
    }
  }->
  if $enable_eosd {
    service { "eosd":
      hasrestart => true,
      ensure     => true,
      enable     => true,
      hasstatus  => true,
      require    => Package['eos-client'],
    }
  }
  else {
    service { "eosd":
      hasrestart => true,
      ensure     => false,
      enable     => false,
      hasstatus  => true,
      require    => Package['eos-client'],
    }
  }
  if $login_node {
    file {"/root/bin/clear_eoslog.sh":
      #ensure   =>  absent,
      mode         =>  '755',
      owner        =>  'root',
      group        =>  'root',
      source       =>  "puppet:///modules/${module_name}/clear_eoslog_login.sh",
    }
    cron { clean-eos:
      command => '/root/bin/clear_eoslog.sh',
      user    => 'root',
      hour    => '*',
      minute  => '5',
      require => File['/root/bin/clear_eoslog.sh'],
    }
  }



  #cron { 'clean-eoslog':
    #command => 'find /var/log/eos/fuse -mmin +60   -exec rm -f {} \;',
  #  command => 'echo > /var/log/eos/fuse/fuse.hxmt.log； eos > /var/log/eos/fuse/fuse.main.log; eos > /var/log/eos/fuse/fuse.public.log',
  #  user    => 'root',
  #  hour    => '*/12',
  #  minute  => '22', 
  #}
  }
else {
   package { "eos-config":
      ensure   => "absent",
   }

  package { ["eos-fuse-core",
             "eos-client",
             "eos-fuse-sysv"]:
      ensure   => "absent",
  }
}
}
}
